<?php
namespace app\index\controller;

use think\Request;
use app\common\model\Enroll as EnrollModel;
use app\common\model\Exhibition as ExhibitionModel;

class Enroll extends Base{

    /**
     * 获取我报名的团购活动
     * @param  Request $request
     * @throws
     */
    public function myEnroll(Request $request){
        $page_size = 10;
        $page = $request -> param('page',0);
        $enroll = EnrollModel::where(['user_id'=>$this->user->id])->order('id desc')->limit($page * $page_size, 10 )->select();
        $exhibition_ids = [];
        foreach($enroll as $key => $item){
            array_push($exhibition_ids,$item['exhibition_id']);
        }
        $exhibition_list = ExhibitionModel::where('id','in',$exhibition_ids)->order('exhibition_time desc')->column("id,title,exhibition_time,state",'id');
        foreach($exhibition_list as &$exhibition){
            $exhibition['exhibition_time'] = date('Y-m-d',$exhibition['exhibition_time']);
        }

        $this->success("获取信息成功",'',$exhibition_list);
    }


    /**
     * 报名的详细信息
     * @param Request $request
     * @throws
     */
    public function detail(Request $request){
        $id = $request->param('id');
        $enroll = EnrollModel::where(['exhibition_id'=>$id,'user_id'=>$this->user->id])->find();
        $exhibition = ExhibitionModel::get($enroll->exhibition_id);
        $enroll->add_time = date('Y-m-d',$enroll->add_time);
        $exhibition->exhibition_time =date('Y-m-d',$exhibition->exhibition_time);
        $data = [
            'enroll'=>$enroll,
            'exhibition'=>$exhibition
        ];

        $this->success("获取信息成功",'',$data);
    }
}